package permissions

import (
	"context"
	"github.com/gogf/gf/v2/frame/g"
	"goAdminV1/internal/model"
	"goAdminV1/utility"

	"goAdminV1/api/permissions/v1"
)

func (c *ControllerV1) JobDisable(ctx context.Context, req *v1.JobDisableReq) (res *v1.JobDisableRes, err error) {
	// 查询岗位详情
	job, err := model.GetJobById(ctx, req.Id)
	if err != nil {
		return nil, utility.Error(utility.CodeOperation, err)
	}

	// 根据 status 值进行切换
	newStatus := 1
	if job.Status == 1 {
		newStatus = 2
	}
	// 构造更新所需的数据
	updateData := g.Map{
		"id":     req.Id,
		"status": newStatus,
	}

	// 调用 model 中的更新方法
	err = model.UpdateJobStatus(ctx, updateData)
	if err != nil {
		return nil, utility.Error(utility.CodeOperation, err)
	}
	return &v1.JobDisableRes{}, nil
}
